def proverka_na_prostotu(x):
    b = 0
    d = 0
    while b!=x:
        b+=1
        if x%b==0:
            d+=1
    if d==2:
        return x
    else:
        return 0


a=int(input())
g = proverka_na_prostotu(a)
h = proverka_na_prostotu(a//10)
n = proverka_na_prostotu(a//100)
p = proverka_na_prostotu(a//1000)
if 1000<=a<=9999:
    print(max(g,h,n,p))
else:
    print(0)
